package ran.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ran.constants.RedisCacheConstants;
import ran.domain.exam.entity.Exam;
import ran.redis.service.RedisService;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-11-10
 * Time: 16:57
 */
@Component
public class ExamRedisManager {
    @Autowired
    private RedisService redisService;
    public void addCache(Exam exam) {
        redisService.leftPushForList(getListKey(),exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()),exam);
    }

    public void deleteCache(Long examId) {
        redisService.removeForList(getListKey(),examId);
        redisService.deleteObject(getDetailKey(examId));
        redisService.deleteObject(getExamQuestionListKey(examId));
    }

    private String getListKey() {
        return RedisCacheConstants.EXAM_UNFINISHED_LIST;
    }
    private String getDetailKey(Long examId) {
        return RedisCacheConstants.EXAM_DETAIL + examId;
    }
    private String getExamQuestionListKey(Long examId) {
        return RedisCacheConstants.EXAM_QUESTION_LIST + examId;
    }
}
